import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;

/**
 * @author liuchaoqun
 * @date 2022/7/5
 * @Description reduce操作
 */
public class Reduce {
    public static void main(String[] args) {
        List<Integer> nums = new ArrayList<>();
        nums.add(1);
        nums.add(1);
        nums.add(1);
        nums.add(1);
        nums.add(1);
        Integer sun = nums.stream().reduce(0, (result, elem) -> result + elem);
        System.out.println(sun);

        System.out.println("--------------");

        List<Integer> testList = new ArrayList<>();
        Integer size = 10;
        for (int i = 0; i < size; i++) {
            testList.add(i);
        }
        testList.stream().sorted((o1, o2) -> o2 - o1).findFirst().ifPresent(integer -> System.out.println("第一个元素："+integer));

        System.out.println("-------------skip操作跳过n个元素");
        testList.stream().skip(1).findFirst().ifPresent(i -> System.out.println("跳过第一个元素0"+i));

        System.out.println("-----------flatMap,把流中的集合再转换成流");

    }
}
